import { combineReducers, configureStore } from "@reduxjs/toolkit";
import { persistReducer } from "redux-persist";
import storage from "redux-persist/lib/storage";

import userReducer from "./features/userSlice";

// redux-persist配置
const persistConfig = {
  key: "root", // 给浏览器的DevTools以及相关插件识别的名称
  storage, // 存储方式: 默认localStorage, 可使用serissonStore浏览器会话级别存储
};

// 合并 reducer
const rootReducer = combineReducers({
  user: userReducer,
});

const reducer = persistReducer(persistConfig, rootReducer);

export default configureStore({
  reducer: reducer,
  middleware: (getDefaultMiddleware) => [
    ...getDefaultMiddleware({
      serializableCheck: false,
    }),
  ],
});
